#include <iostream>
using std::cout;
using std::endl;
//派生类中持有对象数据成员
//派生类进一步去持有基类的数据成员
class Base{
public:
    Base(int base)
    :_ibase(base)
    {
        cout << "Base(int)" << _ibase << endl;
    }

    ~Base(){
        cout << "~Base()" << _ibase << endl;
    }

private:
    int _ibase;
};
class ThirdObj{
public:
    ThirdObj(int number)
    :_ithird(number)
    {
        cout << "Third(int)" << endl;
    }

    ~ThirdObj(){
        cout << "~ThirdObj()" << endl;
    }
private:
    int _ithird;
};

class Derived : public Base{
public:
    //关注此时不同的情形下初始化列表的写法
    //基类的部分：吸收基类的部分，调用基类的构造函数完成这部分的初始化
    //_to对象数据成员：需要调用它的构造函数来完成其初始化
    //其中关于基类部分的构造函数一共有两种写法：
    //Base(base)调用基类的构造函数
    //_base(base * 2)给基类数据成员进行初始化
    Derived(int base,int thirdNumber, int derivedNumber)
    :Base(base)
    ,_to(thirdNumber)
    ,_derivedNumber(derivedNumber)
    ,_base(base * 2)
    {
        cout << "Derived(int,int,int)" << endl;
    }
    ~Derived(){
        cout << "~Derived()" << endl;
    }

private:
    ThirdObj _to;
    int _derivedNumber;
    Base _base;
};


void test(){
    Derived d(1, 2, 3);
}

int main()
{
    test();
    return 0;
}

